﻿using System;
using System.Linq;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Mono.Cecil;
using NDasm.Core.UI.Base;

namespace NDasm.Core.UI.Tree
{
    public class AssemblyNodeViewModel : HierarchicalViewModel
    {
        private readonly ModuleDefinition moduleDefinition;
        private static BitmapImage glyph = new BitmapImage(new Uri("/NDasm.Core;component/Resources/assemblyGlyph.png", UriKind.Relative));

        public AssemblyNodeViewModel(ModuleDefinition moduleDefinition, string scope) : base(scope)
        {
            this.moduleDefinition = moduleDefinition;
            FillTypes();
        }

        public string Name
        {
            get { return moduleDefinition.Name; }
        }

        public override ImageSource Glyph
        {
            get { return glyph; }
        }

        private void FillTypes()
        {
            children.Clear();
            foreach (TypeDefinition type in moduleDefinition.Types.OrderBy(t => t.Name))
                children.Add(new TypeNodeViewModel(type, scope));
        }
    }
}
